<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  install
 */

class m_install_actions_GetModuleMediaAction extends f_core_Action
{
	public function execute()
	{
        $imageFile = MODULES_DIR.DS.'install'.DS.'medias'.DS.$this->getRequestParameter('mediaName');

        if(is_file($imageFile))
        {
            $imageinfo = getimagesize($imageFile);

            if($imageinfo)
            {
                switch($imageinfo[2])
                {
                    case 1:
                        $imagetype = "gif";
                    break;

                    case 2:
                         $imagetype = "jpeg";
                    break;

                    case 3:
                         $imagetype = "png";
                    break;

                    default:
                         header( "HTTP/1.0 404 Not Found" );
                         exit;
                    break;
                }
 
                header( "Content-type: image/$imagetype" );
            }
            else
            {
                $fileO = f_file_File::getInstance($imageFile);
                if($fileO->getMimeType() != '')
                {
                     header("Content-type: ".$fileO->getMimeType());
                }
                else
                {
                     header( "HTTP/1.0 404 Not Found" );
                     exit;
                }
            }
            if(intval(ini_get('output_buffering')) == true)
            {
                ob_clean();
            }
			flush();   
            @readfile( $imageFile );
        }
        else
        {
             header( "HTTP/1.0 404 Not Found" );
             exit;
        }
	}
}